package com.vgemv.jsutilitysdkdemo.module.Screen;

import android.content.Context;
import android.graphics.Canvas;
import android.view.View;

import com.vgemv.jsutilitysdk.log.JsLogManager;
import com.vgemv.jsutilitysdk.JsThread.JsThreadManager;


/*
runloop 0   : TextView创建
runloop1   onMeasure,onMeasure,onLayout,onDraw


 */

public class TestView extends View {
    public int mi_runloopCount = 0;

    public TestView(Context context) {
        super(context);
        JsThreadManager.runInMainThreadAtNextRunloop(new Runnable() {
            @Override
            public void run() {
                mi_runloopCount ++;
                JsLogManager.logc_d("Screen/TestView-NextRunloop","runloop is %d",mi_runloopCount);
            }
        });
        JsLogManager.logc_d("Screen/TestView","runloop is %d",mi_runloopCount);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        JsLogManager.logc_d("Screen/onDraw","");
        super.onDraw(canvas);
        JsThreadManager.runInMainThreadAtNextRunloop(new Runnable() {
            @Override
            public void run() {
                mi_runloopCount ++;
                JsLogManager.logc_d("Screen/onDraw-NextRunloop","runloop is %d",mi_runloopCount);
            }
        });
        JsLogManager.logc_d("Screen/onDraw","runloop is %d",mi_runloopCount);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        JsLogManager.logc_d("Screen/onMeasure","widthMeasureSpec:%d,heightMeasureSpec:%d",widthMeasureSpec,heightMeasureSpec);
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        JsLogManager.logc_d("Screen/onMeasure","width:%d,height:%d",getMeasuredWidth(),getMeasuredHeight());
        JsThreadManager.runInMainThreadAtNextRunloop(new Runnable() {
            @Override
            public void run() {
                mi_runloopCount ++;
                JsLogManager.logc_d("Screen/onMeasure-NextRunloop","runloop is %d",mi_runloopCount);
            }
        });
        JsLogManager.logc_d("Screen/onMeasure","runloop is %d",mi_runloopCount);
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        JsLogManager.logc_d("Screen/onLayout","left:%d,top:%d,top:%d,bottom:%d",left,top,right,bottom);
        super.onLayout(changed, left, top, right, bottom);
        JsThreadManager.runInMainThreadAtNextRunloop(new Runnable() {
            @Override
            public void run() {
                mi_runloopCount ++;
                JsLogManager.logc_d("Screen/onLayout-NextRunloop","runloop is %d",mi_runloopCount);
            }
        });
        JsLogManager.logc_d("Screen/onLayout","runloop is %d",mi_runloopCount);
    }
}
